<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理用户页面</title>
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <script src="${APP_PATH}/static/js/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet"
          href="${APP_PATH}/static/bootstrap-3.4.1-dist/css/bootstrap.min.css">
    <script
            src="${APP_PATH}/static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 搭建显示页面 -->
<div class="container">
    <!-- 标题行 -->
    <div class="row">
        <div class="col-xs-12">
            <h1>管理员页面</h1>
        </div>
    </div>
    <div class="row">
			<div class="col-md-10">
				<form action="${APP_PATH}/something/administrator">
					<button type="submit" class="btn btn-success">管理页面</button>
				</form>
			</div>
		</div>
    <!-- 按钮 -->
    <!-- <div class="row">
        <div class="col-md-4 col-md-offset-8">
            <button class="btn btn-primary">新增</button>
            <button class="btn btn-danger">删除</button>
        </div>
    </div> -->
    <!-- 显示表格数据 -->
    <div class="row">
        <div class="col-md-12">
            <!-- 按钮 -->
            <div class="row">
                <div class="col-md-4 col-md-offset-8">
                    <!-- <button class="btn btn-primary" id="insert_btn">新增</button> -->
                    <button class="btn btn-primary" data-toggle="modal"
                            data-target="#myModal">
                        <span class="glyphicon glyphicon-plus">增加</span>
                    </button>
                    <!-- 增加——模态框 -->
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-hidden="true">×
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">新增用户</h4>
                                </div>
                                <div class="modal-body">
                                    <!-- form表单 -->
                                    <form action="${APP_PATH}/user/insertUser" method="post">
                                        用户姓名：<input type="text" name="name" placeholder="用户姓名" required="required"><br>
                                        <br>
                                        用户密码：<input type="text" name="password" placeholder="用户密码"
                                                    required="required"><br>
                                        <br>
                                        用户身份证号：<input type="text" name="idcard" placeholder="用户身份证号"
                                                      required="required"><br>
                                        <br>
                                        用户手机号：<input type="text" name="phone" placeholder="用户手机号"
                                                     required="required"><br>
                                        <br>
                                        <input type="submit" class="btn btn-default" value="提交"/>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default"
                                            data-dismiss="modal">关闭
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <table class="table table-hover">
                <tr>
                    <th>id</th>
                    <th>name</th>
                    <th>password</th>
                    <th>idcard</th>
                    <th>phone</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${pageInfo.list }" var="user">
                    <tr>
                        <th>${user.id}</th>
                        <th>${user.name}</th>
                        <th>${user.password}</th>
                        <th>${user.idcard}</th>
                        <th>${user.phone}</th>
                        <th>
                            <button class="btn btn-primary btn-sm" data-toggle="modal"
                                    data-target="#myEditModal" onclick="Values(${user.id})">
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true"
                                      >编辑</span>
                            </button>

                            <div class="modal fade" id="myEditModal" tabindex="-1"
                                 role="dialog">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                            <h4 class="modal-title">修改信息</h4>
                                        </div>
                                        <div class="modal-body">
                                            <form
                                                    action="${APP_PATH}/user/editUser"
                                                    method="post">
                                                <input type="hidden" id="id1" name="id" value="">
                                                用户姓名：<input type="text" name="name" placeholder="用户姓名"
                                                            required="required"><br> <br>
                                                用户密码：<input type="text" name="password" placeholder="用户密码"
                                                            required="required"><br> <br>
                                                用户身份证号：<input type="text" name="idcard" placeholder="用户身份证号"
                                                              required="required"><br> <br>
                                                用户手机号：<input type="text" name="phone" placeholder="用户手机号"
                                                             required="required"><br> <br>
                                                <input type="submit" value="提交" class="btn btn-default">
                                            </form>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default"
                                                    data-dismiss="modal">关闭
                                            </button>
                                        </div>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal-dialog -->
                            </div>


                            <button class="btn btn-danger btn-sm" data-toggle="modal"
                                    data-target="#myDeleteModal" onclick="Values(${user.id})">
                                <span class="glyphicon glyphicon-trash" aria-hidden="true"
                                      >删除</span>
                            </button>
                            <div class="modal fade" id="myDeleteModal" tabindex="-1"
                                 role="dialog">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                            <h4 class="modal-title">删除信息</h4>
                                        </div>
                                        <div class="modal-body">
                                            <form action="${APP_PATH}/user/deleteUser"
                                                  method="post">
                                                <input type="hidden" id="id2" name="id" value="">
                                                <input type="submit" value="删除" class="btn btn-default">
                                            </form>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default"
                                                    data-dismiss="modal">关闭
                                            </button>
                                        </div>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal-dialog -->
                            </div>


                            <form action="${APP_PATH}/user/downloadlicense?license=${user.license}" method="post">
                                <input class="btn btn-success btn-sm" type="submit" value="下载">
                            </form>
                                <%--  <button class="btn btn-danger btn-sm" id="down_btn"
                                          onclick="downloadPass('${user.license}')">
                                          <span class="glyphicon glyphicon-trash" aria-hidden="true">下载驾照
                                          </span>
                                  </button>--%>
                        </th>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
    <!-- 分页信息 -->
    <div class="row">
        <!-- 分页文字信息 -->
        <div class="col-md-6">当前${pageInfo.pageNum }页,总${pageInfo.pages }页,总${pageInfo.total }条记录
        </div>
        <!-- 分页条信息 -->
        <div class="col-md-6">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li><a href="${APP_PATH }/user/selectAll?pn=1">首页</a></li>
                    <c:if test="${pageInfo.hasPreviousPage }">
                        <li><a href="${APP_PATH }/user/selectAll?pn=${pageInfo.pageNum-1}"
                               aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
                        </a></li>
                    </c:if>
                    <c:forEach items="${pageInfo.navigatepageNums }" var="page_Num">
                        <c:if test="${page_Num == pageInfo.pageNum }">
                            <li class="active"><a href="#">${page_Num }</a></li>
                        </c:if>
                        <c:if test="${page_Num != pageInfo.pageNum }">
                            <li><a href="${APP_PATH }/user/selectAll?pn=${page_Num}">${page_Num}</a></li>
                        </c:if>
                    </c:forEach>
                    <c:if test="${pageInfo.hasNextPage }">
                        <li><a href="${APP_PATH }/user/selectAll?pn=${pageInfo.pageNum+1}" aria-label="Next"> <span
                                aria-hidden="true">&raquo;</span>
                        </a></li>
                    </c:if>
                    <li><a href="${APP_PATH }/user/selectAll?pn=${pageInfo.pages}">末页</a></li>
                </ul>
            </nav>
        </div>
    </div>
</div>
<script type="text/javascript">
    /*发送下载驾照请求*/
    function downloadPass(license) {
        if (confirm("确认下载？")) {
            $.ajax({
                url: "${APP_PATH}/user/downloadlicense",
                data: {"license": license},
                type: "POST",
                // success: function (data) {
                //     if (data == "OK") {
                //         alert("下载成功");
                //         window.location.reload();
                //     } else {
                //         alert("下载失败");
                //         window.location.reload();
                //     }
                // }
            })
            ;
        }
    }

/*     $("#myEditModal").modal("hide");
    $("#myDeleteModal").modal("hide");
 */
    function Values(id) {
        $("#id1").val(id);
        $("#id2").val(id);
    }

</script>
</body>
</html>